package jianzhi_offer;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Queue;

/**
 * @author: zhouyang
 * @descrpition:
 * @time: 2019-04-16 13:52
 */
public class _59_把二叉树打印成多行 {
    ArrayList<ArrayList<Integer>> Print(TreeNode pRoot) {
        ArrayList<ArrayList<Integer>> res = new ArrayList<ArrayList<Integer>>();
        if(pRoot == null) return res;
        Queue<TreeNode> queue = new LinkedList<>();
        queue.offer(pRoot);
        while (!queue.isEmpty()){
            ArrayList<Integer> now  = new ArrayList<>();
            int size = queue.size();
            while(size > 0){
                TreeNode node = queue.poll();
                now.add(node.val);
                if(node.left != null) queue.offer(node.left);
                if(node.right != null) queue.offer(node.right);
                --size;
            }
            res.add(now);
        }
        return res;
    }
}
